package com.qf.util;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * IntelliJ IDEA -> springboot120622
 * 2019/12/7 1:15
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Configuration
public class SringQuartzTaskConfig {
    //任务
    @Bean
    public MethodInvokingJobDetailFactoryBean a1(SpringQuartzTask  task){
        MethodInvokingJobDetailFactoryBean factoryBean = new MethodInvokingJobDetailFactoryBean();
        factoryBean.setTargetObject(task);
        factoryBean.setTargetMethod("myjob");
        return  factoryBean;
    }

    //触发器
    @Bean
    public CronTriggerFactoryBean b1(MethodInvokingJobDetailFactoryBean fb){
        CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
        factoryBean.setJobDetail(fb.getObject());
        factoryBean.setCronExpression("* * * * * ?");
        return  factoryBean;
    }

    //调度器
    @Bean
    public SchedulerFactoryBean c1(CronTriggerFactoryBean fb) {
        SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
        factoryBean.setTriggers(fb.getObject());
        return factoryBean;
    }
}
